import request from "@/util/request";

// 查询联系人列表
export const getContactListApi = (userId: number) => {
  return request({
    url: `/contacts/list`,
    method: "get",
    params: { userId },
  });
};

export const addContactApi = (userId: number, data: any) => {
  return request({
    url: `/contacts/add`,
    method: "post",
    params: { userId },
    data,
  });
};

export const updateContactApi = (
  userId: number,
  friendId: number,
  data: any
) => {
  return request({
    url: `/contacts/update`,
    method: "put",
    params: { userId, friendId },
    data,
  });
};

export const deleteContactApi = (userId: number, friendId: number) => {
  return request({
    url: `/contacts/delete`,
    method: "delete",
    params: { userId, friendId },
  });
};

// // 添加删除联系人的 API
// export function deleteContactApi(userId: number, contactId: number) {
//   return request({
//     url: `/contact/${userId}/delete/${contactId}`,
//     method: 'delete'
//   });
// }

// 获取待处理的好友请求
export const getPendingRequests = (userId: number) => {
  return request({
    url: "/contacts/requests",
    method: "get",
    params: { userId },
  });
};

// 处理好友请求
export const handleFriendRequest = (
  userId: number,
  requestId: number,
  accept: boolean
) => {
  return request({
    url: "/contacts/request/handle",
    method: "post",
    params: { userId, requestId, accept },
  });
};

// 发送好友请求
export const sendFriendRequest = (userId: number, requestData: any) => {
  return request({
    url: "/contacts/request",
    method: "post",
    params: { userId },
    data: requestData,
  });
};
